package com.demo.project_template.controller;

import com.demo.project_template.base.pay.wxpay.vo.DecryptWeChartMsgVO;
import com.demo.project_template.entity.SysUser;
import com.demo.project_template.entity.User;
import com.demo.project_template.service.LoginService;
import com.demo.project_template.vo.request.user.UserLoginVO;
import com.demo.project_template.vo.response.LoginResponseVo;
import com.demo.project_template.vo.response.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;
import java.util.HashMap;


/**
 * @author yyl25
 */
@Api(tags = "登录模块")
@RestController
@RequestMapping("/login")
public class LoginController {
    @Resource
    private LoginService loginService;


    @ApiOperation("用户登录")
    @PostMapping("/user")
    public R<LoginResponseVo> user(@RequestBody UserLoginVO userLoginVO) {
        return R.success(loginService.userLogin(userLoginVO));
    }

    @ApiOperation(value = "获取验证码")
    @GetMapping(value = "/sendCaptcha")
    public R<String> sendCaptcha(@RequestParam String phoneNumber){
        //接入短信
        loginService.sendCaptcha(phoneNumber);
        return R.success();
    }

    @ApiOperation(value = "后台登录")
    @PostMapping("/sys")
    public R<LoginResponseVo> sys(@RequestBody SysUser user){
        return R.success(loginService.sysLogin(user));
    }

    @ApiOperation(value = "后台退出")
    @PostMapping("/logout")
    public R<?> logout(){
        loginService.logout();
        return R.success();
    }
}
